const regExp = {
  //校验统一社会信用代码
  validateCreditCode(code) {
    return RegExp(/^([0-9A-HJ-NPQRTUWXY]{2}\d{6}[0-9A-HJ-NPQRTUWXY]{10}|[1-9]\d{14})$/).test(
      code);
  },
  //校验银行卡号
  validateBankCardNumber(bankCardNumber) {
    return RegExp(/^[1-9]\d{9,29}$/).test(bankCardNumber);
  },
  //校验身份证号
  validateIdNumber(idNumber) {
    return RegExp(/^[1-9]\d{5}(?:18|19|20)\d{2}(?:0[1-9]|10|11|12)(?:0[1-9]|[1-2]\d|30|31)\d{3}[\dXx]$/).test(
      idNumber);
  },
  //校验手机号
  validatePhone(phone) {
    return RegExp(/^(?:(?:\+|00)86)?1(?:(?:3[\d])|(?:4[5-79])|(?:5[0-35-9])|(?:6[5-7])|(?:7[0-8])|(?:8[\d])|(?:9[189]))\d{8}$/).test(phone);
  },
  //校验座机号
  validateTelPhone(telPhone) {
    return RegExp(/^[0][1-9]{2,3}-[0-9]{5,10}$/).test(telPhone);
  },
  //校验邮箱
  validateEmail(email) {
    return RegExp(/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/).test(
      email);
  },
  //校验纯正整数
  validateNumber(number) {
    return RegExp(/^[0-9]*$/).test(
      number);
  },
  //校验纯正整数，且至多保留两位小数
  validateInteger(number) {
    return RegExp(/(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/).test(
      number);
  },
  //校验正实数，且至多保留两位小数
  validateRealNumber(number) {
    return RegExp(/^(([1-9][0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2})))$/).test(
      number);
  },
  //校验强密码，需包含数字、字母、特殊符号，长度6-10位
  validatePassword(password) {
    return RegExp(/^(?=.*[a-zA-Z])(?=.*\d)(?=.*[~!@#$%^&*()_+`\-={}:";'<>?,.\/]).{6,10}$/).test(
      password);
  },
  //校验密码，需包含数字、字母，长度6位以上
  validatePassword2(password) {
    return RegExp(/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,}$/).test(
      password);
  }
}

module.exports = {
  validateCreditCode: regExp.validateCreditCode,
  validateBankCardNumber: regExp.validateBankCardNumber,
  validateIdNumber: regExp.validateIdNumber,
  validatePhone: regExp.validatePhone,
  validateTelPhone: regExp.validateTelPhone,
  validateEmail: regExp.validateEmail,
  validateNumber: regExp.validateNumber,
  validateInteger: regExp.validateInteger,
  validateRealNumber: regExp.validateRealNumber,
  validatePassword: regExp.validatePassword,
  validatePassword2: regExp.validatePassword2
}